package com.kzd.btgame.jetpack.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.kzd.btgame.base.BaseViewModel
import com.kzd.btgame.entity.*
import com.kzd.btgame.jetpack.api.*
import com.module.lemlin.http.*
import com.module.lemlin.owner.setRxLifeScope

class MineViewModel(application: Application) : BaseViewModel(application) {

    private var page: Int = 1
    private var limit: Int = 10

    val collectGameLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<GameBean>>>()
    fun mineCollectGame(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<GameBean>>(collectGameLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<GameBean>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            personalGameCollect(
                page.toString(), limit.toString()
            )
        }
    }

    val collectBargainLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<GameBargain>>>()
    fun mineCollectBargain(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<GameBargain>>(collectBargainLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<GameBargain>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            personalTradeCollect(
                page.toString(), limit.toString()
            )
        }
    }

    val collectGoodsLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<MallGoods>>>()
    fun mineCollectGoods(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<MallGoods>>(collectGoodsLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<MallGoods>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            personalGoodsCollect(
                page.toString(), limit.toString()
            )
        }
    }

    val couponPriceLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<WelfareCoupon>>>()
    fun mineCouponPrice(type: Int, isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<WelfareCoupon>>(couponPriceLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<WelfareCoupon>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            userMyCoupon(
                type.toString(), page.toString(), limit.toString()
            )
        }
    }

    val giftListMyLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<GameGift>>>()
    fun mineGiftList(keyword: String? = null, isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<GameGift>>(giftListMyLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<GameGift>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            personalMyGift(
                keyword, page.toString(), limit.toString()
            )
        }
    }

    val feedbackTypeLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<FeedbackType>>>()
    fun mineFeedbackType() {
        setRxLifeScope(SubscribeViewModel(feedbackTypeLiveData)) {
            userGetFeedbackTypes()
        }
    }

    val memberMoneyCardLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<MemberMoney>>>()
    fun mineMemberMoneyCard() {
        setRxLifeScope(SubscribeViewModel(memberMoneyCardLiveData)) {
            userGetSavingInfo()
        }
    }

    val moneyOrderLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<String>>>()
    fun mineMemberMoneyOrder(type: String, money: String, pay_type: String) {
        setRxLifeScope(SubscribeViewModel(moneyOrderLiveData)) {
            userSavingApply(type, money, pay_type)
        }
    }

    val memberCenterCardLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<MemberCenter>>>()
    fun mineMemberCenterCard() {
        setRxLifeScope(SubscribeViewModel(memberCenterCardLiveData)) {
            userGetMemberInfo()
        }
    }

    val centerOrderLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<String>>>()
    fun mineMemberCenterOrder(id: String, money: String, pay_type: String) {
        setRxLifeScope(SubscribeViewModel(centerOrderLiveData)) {
            userMemberCreateOrder(id, money, pay_type)
        }
    }

    val platformMoneyLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<PlatformData>>>()
    fun minePlatformMoney() {
        setRxLifeScope(SubscribeViewModel(platformMoneyLiveData)) {
            userGetCoinInfo()
        }
    }

    val platformOrderLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<String>>>()
    fun minePlatformOrder(id: String, money: String, pay_type: String,is_have:Int = 0) {
        setRxLifeScope(SubscribeViewModel(platformOrderLiveData)) {
            userCoinCreateOrder(id, money, pay_type,is_have)
        }
    }


    val transferListLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<GameBean>>>()
    fun mineTransferList(keyword: String = "", isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<GameBean>>(transferListLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<GameBean>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            newGetTurnList(
                keyword, page.toString(), limit.toString()
            )
        }
    }


    val transferDetailsLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<GameTransfer>>>()
    fun mineTransferDetails(game_id: String) {
        setRxLifeScope(SubscribeViewModel(transferDetailsLiveData)) {
            newGetTurnDetail(game_id)
        }
    }

    val transferInfoLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataT<TransferInfo>>>()
    fun mineTransferInfo(game_id: String) {
        setRxLifeScope(SubscribeViewModel(transferInfoLiveData)) {
            personalGetTurnInfo(game_id)
        }
    }

    val transferRoleLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<TransferRole>>>()
    fun mineTransferRole(appid: String, servers_id: String? = null) {
        setRxLifeScope(SubscribeViewModel(transferRoleLiveData)) {
            personalGetRoleList(appid, servers_id)
        }
    }

    val transferApplyLiveData = MutableLiveData<HttpResponseBody<HttpResponseData>>()
    fun mineTransferApply(
        gid: String, roleid: String, turn_gid: String, turn_roleid: String
    ) {
        setRxLifeScope(SubscribeViewModel(transferApplyLiveData)) {
            personalSetTurn(gid, roleid, turn_gid, turn_roleid)
        }
    }

    val myGameLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<GameBean>>>()
    fun mineMyGame() {
        setRxLifeScope(SubscribeViewModel(myGameLiveData)) {
            userMyGame()
        }
    }


    val mineDiscussLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<MineDiscuss>>>()
    fun mineMyDiscuss(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<MineDiscuss>>(mineDiscussLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<MineDiscuss>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            newMyDiscuss(
                page.toString(), limit.toString()
            )
        }
    }


    val mineOrderLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<MineOrder>>>()
    fun mineMyOrder(type: Int, isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<MineOrder>>(mineOrderLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<MineOrder>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            personalGetMyOrder(
                type, page.toString(), limit.toString()
            )
        }
    }

    val myLotteryLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<MineLottery>>>()
    fun mineMyLottery(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<MineLottery>>(myLotteryLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<MineLottery>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            appLotteryLog(
                page.toString(), limit.toString()
            )
        }
    }


    val userMessageLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<UserMessage>>>()
    fun mineMessage(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<UserMessage>>(userMessageLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<UserMessage>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            newMessage(
                page.toString(), limit.toString()
            )
        }
    }

    val mineMessageReadLiveData = MutableLiveData<HttpResponseBody<HttpResponseData>>()
    fun mineMessageRead() {
        setRxLifeScope(SubscribeViewModel(mineMessageReadLiveData)) {
            newMessageRead()
        }
    }

    val mineFeedbackLiveData = MutableLiveData<HttpResponseBody<HttpResponseData>>()
    fun mineFeedback(feedback: Feedback) {
        setRxLifeScope(SubscribeViewModel(mineFeedbackLiveData)) {
            userFeedback(feedback)
        }
    }


    val gameFeedbackLiveData = MutableLiveData<HttpResponseBody<HttpResponseDataE<GameFeedback>>>()
    fun mineFeedbackGame(isLoadMore: Boolean = false) {
        setRxLifeScope(object : SubscribeViewModel<HttpResponseDataE<GameFeedback>>(gameFeedbackLiveData) {
            override fun onSuccess(resp: HttpResponseDataE<GameFeedback>) {
                super.onSuccess(resp.apply {
                    this.isLoadMore = isLoadMore
                })
                page += 1
            }
        }) {
            if (!isLoadMore) {
                page = 1
            }
            newGetGameList(
                page.toString(), limit.toString()
            )
        }
    }
}